/**
 * <p>格式化的辅组类</p>
 * xtype = cceafformathelper

 * @module Ext-ux-cceaf-util
 * @class cceaf.util.FormatHelper
 * @extends Object
 * @static
 * @since 1.0
 */
Ext.ns('cceaf.util');

Ext.define('cceaf.util.FormatHelper',{
	//extjs cmd只能通过类查找，需定义空类
});

cceaf.util.FormatHelper = (function() {
	
	return {
		
		/**
		 * 格式化数值型数据
		 * @param val 数值
		 * @param digits 小数位数
		 * @param display 是否必须显示小数部分的尾部零
		 */
		formatFloat: function(val, digits, display) {
			var result = "";
			var divisor = Math.pow(10, digits);
			if (isNaN(val)){
				val = 0;
			}
			var sign = (val == Math.abs(val));
			val = Math.abs(val);
			val = Math.floor(val * divisor + 0.5);
			if (display == false){
				result = (sign ? "" : "-") + val / divisor;
			}
			else{
				var fraction = val % divisor;
				val = Math.floor(val / divisor);
				var len = fraction.toString().length;
				for(var i = 0; i < digits - len; i++){
					fraction = "0" + fraction;
				}
				result = (sign ? "" : "-") + val + "." + fraction;
			}
			return result;
		}
		
	};
	
}());
